using UnityEngine;
using UnityEngine.UI;

public class HUDController : MonoBehaviour
{
    [Header("Health UI")]
    [SerializeField] private Image healthUIBar;
    [SerializeField] private PlayerDamager playerDamage;
    [SerializeField] private float smoothSpeed = 5f;

    [Header("Wave UI")]
    [SerializeField] private Text waveText;

    private float targetFill;

    private void Awake()
    {
        playerDamage = FindAnyObjectByType<PlayerDamager>();
    }

    void Start()
    {
        healthUIBar.fillAmount = 1f;
    }

    void Update()
    {
        UpdateHealthBar();
        UpdateWaveText();
    }

    private void UpdateHealthBar()
    {
        targetFill = (float)playerDamage.CurrentHealth() / playerDamage.MaxHealth();

        healthUIBar.fillAmount = Mathf.Lerp(
            healthUIBar.fillAmount,
            targetFill,
            Time.deltaTime * smoothSpeed
        );
    }

    private void UpdateWaveText()
    {
        if (waveText != null && ProgressiveWaveManager.Instance != null)
        {
            int currentWave = ProgressiveWaveManager.Instance.GetCurrentWave();
            waveText.text = $"Wave: {currentWave}";
        }
    }
}